const path = require('path');

// HtmlWebpackPlugin 自动设定 html引进的js文件名，不会重命名
const HtmlWebpackPlugin = require('html-webpack-plugin');

// clean-webpack-plugin 是一个比较普及的管理插件
const CleanWebpackPlugin = require('clean-webpack-plugin');

const webpack = require('webpack');


module.exports = {
  entry: {
    app: './src/index.js'
    // print: './src/print.js'
  },
  // 错误追踪 用在开发环境
  devtool: 'inline-source-map',
  // 用webpack-dev-server启动模式    webpack-dev-server和webpack-dev-middleware只能用一个模式
  devServer: {
    contentBase: './dist',
    hot: true
  },
  // 插件
  plugins: [
    new CleanWebpackPlugin(['dist']),
    new HtmlWebpackPlugin({
      title: 'Output Management'
    }),
    new webpack.NamedModulesPlugin(), 
    new webpack.HotModuleReplacementPlugin()
  ],
  output: {
    // filename: 'bundle.js',
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist')
    // 用webpack-dev-middleware启动模式    webpack-dev-server和webpack-dev-middleware只能用一个模式
    // publicPath: '/'
  },
  mode: "production",
  module: {
    rules: [{ // 加载 CSS
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      { // 加载图片
        test: /\.(png|svg|jpg|gif)$/,
        use: ['file-loader']
      },
      { // 加载字体
        test: /\.(woff|woff2|eot|TTF|otf)$/,
        use: ['file-loader']
      },
      { // 加载数据
        test: /\.(csv|tsv)$/,
        use: ['csv-loader']
      },
      {
        test: /\.xml$/,
        use: ['xml-loader']
      }
    ],

  }
};